#ifdef MPI
#ifdef DEBUG_MPI
 printf("Entering MPI in heat_2d_eq \n");
fflush(stdout);
#endif

    int tag;
    int grid_to;
    int grid_from;
    MPI_Status status;

    MPI_Request reqs[N_FIELDS_MPI*2*DIM*N_GRIDS],  reqr[N_FIELDS_MPI*2*DIM*N_GRIDS];



#ifdef DEBUG_MPI
 printf("Before sending-receiving \n");
fflush(stdout);
#endif

  /* ----------------------- receive and send stencils from other grids ------------------------------------ */

 {int field; 
 for (field = 0; field < N_FIELDS_MPI; field++){

#ifdef DEBUG_MPI
/*  printf("n%d send side 0 of field %d to grid %d with tag %d\n", grid, field, (*grid_ptr).grid_from_g_c_s_recv[grid][0][0], 2*field+1 ); */
/*  printf("n%d send side 1 of field %d to grid %d with tag %d\n", grid, field, (*grid_ptr).grid_from_g_c_s_recv[grid][0][1], 2*field ); */
#endif
     grid_from=(*grid_ptr).gcs_recv[grid][0][0].g;
     tag=2*DIM*N_GRIDS*field + 2*DIM*grid;
     MPI_Irecv(sfield_recv.s_x_0_u[field],n_gridpts_2, MPI_DOUBLE,  grid_from, tag, global, &reqr[tag]);

     grid_from=(*grid_ptr).gcs_recv[grid][0][1].g;
     tag=2*DIM*N_GRIDS*field + 2*DIM*grid + 1;
     MPI_Irecv(sfield_recv.s_x_1_u[field],n_gridpts_2, MPI_DOUBLE, grid_from, tag, global, &reqr[tag]);
 
     grid_from=(*grid_ptr).gcs_recv[grid][1][0].g;
     tag=2*DIM*N_GRIDS*field + 2*DIM*grid + 2;
     MPI_Irecv(sfield_recv.s_y_0_u[field],n_gridpts_1, MPI_DOUBLE,  grid_from, tag, global, &reqr[tag]);

     grid_from=(*grid_ptr).gcs_recv[grid][1][1].g;
     tag=2*DIM*N_GRIDS*field + 2*DIM*grid + 3;
     MPI_Irecv(sfield_recv.s_y_1_u[field],n_gridpts_1, MPI_DOUBLE, grid_from, tag, global, &reqr[tag]);


     grid_to=(*grid_ptr).gcs_send[grid][0][0].g;
     tag=2*DIM*N_GRIDS*field + 2*DIM*grid_to + 2*(*grid_ptr).gcs_send[grid][0][0].c+(*grid_ptr).gcs_send[grid][0][0].s;
     MPI_Isend(sfield_send.s_x_0_u[field],n_gridpts_2, MPI_DOUBLE, grid_to, tag, global, &reqs[tag]);

     grid_to=(*grid_ptr).gcs_send[grid][0][1].g;
     tag=2*DIM*N_GRIDS*field + 2*DIM*grid_to + 2*(*grid_ptr).gcs_send[grid][0][1].c+(*grid_ptr).gcs_send[grid][0][1].s;
     MPI_Isend(sfield_send.s_x_1_u[field],n_gridpts_2, MPI_DOUBLE, grid_to, tag, global, &reqs[tag]);

     grid_to=(*grid_ptr).gcs_send[grid][1][0].g;
     tag=2*DIM*N_GRIDS*field + 2*DIM*grid_to + 2*(*grid_ptr).gcs_send[grid][1][0].c+(*grid_ptr).gcs_send[grid][1][0].s;
     MPI_Isend(sfield_send.s_y_0_u[field],n_gridpts_2, MPI_DOUBLE, grid_to, tag, global, &reqs[tag]);

     grid_to=(*grid_ptr).gcs_send[grid][1][1].g;
     tag=2*DIM*N_GRIDS*field + 2*DIM*grid_to + 2*(*grid_ptr).gcs_send[grid][1][1].c+(*grid_ptr).gcs_send[grid][1][1].s;
     MPI_Isend(sfield_send.s_y_1_u[field],n_gridpts_2, MPI_DOUBLE, grid_to, tag, global, &reqs[tag]);




/*      MPI_Barrier (global); */

}}


/*  printf("After sending-receiving \n"); */



#endif
